#include<iostream>
#include"Heap.h"
using namespace std;

typedef struct HuffmanTreeNode* HuffmanTree;
struct HuffmanTreeNode
{
	int weight;
	HuffmanTree Left, Right;
};

HuffmanTree Huffman(MinHeap H)
{
	int i; HuffmanTree T;
	Build_MinHeap(H);
	for ( i = 1; i < H->size; i++)
	{
		T = (HuffmanTree)malloc(sizeof(HuffmanTreeNode));
		T->Left->weight = Heap_Delete(H);
		T->Right->weight = Heap_Delete(H);
		T->weight = T->Left->weight + T->Right->weight;
		Heap_insert(H, T->weight);
	}
	T->weight = Heap_Delete(H);
	return T;
}